package cn.bsuc.crm.controller;


import cn.bsuc.crm.dto.CustomerseverDTO;
import cn.bsuc.crm.entity.CustomerServe;
import cn.bsuc.crm.entity.Role;
import cn.bsuc.crm.service.CustomerServeService;
import cn.bsuc.crm.util.Code;
import cn.bsuc.crm.util.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuoyuan
 * @since 2022-10-03
 */
@RestController
@RequestMapping("/customerServe")
@CrossOrigin
public class CustomerServeController {
    @Autowired
    private CustomerServeService customerServeService;

    @RequestMapping("list")
    public Result CustomerServeByParams(@RequestParam(defaultValue = "1") Integer pageNo,
                                        @RequestParam(defaultValue = "3")Integer pageSize,CustomerseverDTO customerseverDtO) {

       Page list =customerServeService.CustomerServeByParams(pageNo,pageSize,customerseverDtO);
return Result.ok(list);

    }

    @RequestMapping("index/{type}")
    public String index(@PathVariable Integer type) {
        // 判断类型是否为空
        if (type != null) {
            if (type == 1) {

                // 服务创建
                return "customerServe/customer_serve";

            } else if (type == 2) {

                // 服务分配
                return "customerServe/customer_serve_assign";

            } else if (type == 3) {

                // 服务处理
                return "customerServe/customer_serve_proce";

            } else if (type == 4) {

                // 服务反馈
                return "customerServe/customer_serve_feed_back";

            } else if (type == 5) {

                // 服务归档
                return "customerServe/customer_serve_archive";

            } else {
                return "";
            }

        } else {
            return "";
        }
    }


    //查询所有角色及分页
    @GetMapping("/selectAllCustomer")
    public Result selectAllRolex(@RequestParam(defaultValue = "1") Integer pageNo,
                                 @RequestParam(defaultValue = "3")Integer pageSize) {
        Page<CustomerServe> ServePage = customerServeService.selectAllServe(pageNo, pageSize);
        return Result.ok(ServePage);

    }

    @RequestMapping("/add")
    public Result insertAdd(@RequestBody CustomerServe customerServe) {
        int i =  customerServeService.insertAdd(customerServe);
        if (i == 0){
            return  Result.fail(Code.ERROR,"保存失败");
        }else {
            return Result.ok(Code.OK,"保存成功");
        }

    }

    @RequestMapping("/update")
    public Result update(CustomerServe customerServe) {
        System.out.println();
        System.out.println(customerServe);
        System.out.println();

        int i = customerServeService.updateService(customerServe);
       if (i != 0){
           return Result.ok(Code.OK,"修改成功");
        }else {
           return Result.fail(Code.ERROR, "修改失败");
       }

    }


    @RequestMapping("/id")
    public Result selectByid(int id) {
        CustomerServe byId = customerServeService.getById(id);
        return  Result.ok(byId);
    }


    @RequestMapping("/chuli")
    public Result selectchuli(String username) {
        List<CustomerServe> chuli = customerServeService.selectchuli(username);
        return  Result.ok(chuli);
    }




}

